package Servlet;

import service.FlightService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteFlightServlet")
public class DeleteFlightServlet extends HttpServlet {

    private FlightService flightService = new FlightService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.  解决乱码：
        request.setCharacterEncoding("UTF-8");

        //1. 接收id
        String id = request.getParameter("id");
        //2. 调用service查询
         flightService.deleteById(Integer.parseInt(id));

        //3. 转发到查询所有Servlet
        request.getRequestDispatcher("/selectFlightServlet").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}